axios.defaults.baseURL = 'http://geek.itheima.net'
axios.interceptors.request.use(function (config){
    const token = localStorage.getItem('token')
    token && (config.headers.Authorization = `Bearer ${token}`)
    return config
})

axios.interceptors.response.use(response => {
// Do something before response is sent
return response;
},error => {
// Do something with response error
    if(error?.response?.status === 401){
        alert("身份验证失败，请重新登陆")
        localStorage.clear()
        location.href = '../login/index.html'
    }
return Promise.reject(error);
});